<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人中心</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/mycenter.css">
    <script src="js/commom.js"></script>
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="/blog/blog_list.html">主页</a>
        <!-- <a href="blog_edit.html">写博客</a> -->
        <a href="/blog/reg.html">注册</a>
        <!-- <a href="#">注销</a> -->
        <script src="js/jquery.min.js"></script>
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <!-- 中间的登陆框 -->
        <div class="login-dialog">
            <h2>找回密码</h2>
               
                <div class="row">
                    <span>账号：</span>
                    <input type="text" id="username">
                </div>
                <div class="row">
                    <span>信息验证: </span>
                
                </div>
                <div class="row">
                    <span>你喜欢的人是谁？: </span>
                    <input type="text" id="lover">
                </div>
            
                <div class="row">
                    <span>修改密码: </span>
                </div>
                <div class="row">     
                    <span>新密码: </span>
                    <input type="password" id="password1" maxlength="10">
                </div>
                <div class="row">
                    <span>确认密码: </span>
                    <input type="password" id="password2" maxlength="10">
                </div>                
                <div class="row">
                    <button id="submit" onclick="findPassword()">保存</button>
                </div>
                
        </div>
    </div>
    <script>
        function findPassword() {
            var username = jQuery("#username");
            var lover = jQuery("#lover");
            var password1 = jQuery("#password1");
            var password2 = jQuery("#password2");
            //1、判空
            if(username.val() == "") {
                alert("请输入需要找回的账号");
                username.focus();
                return;
            }
            if(lover.val() == "") {
                alert("请输入私密信息");
                lover.focus();
                return;
            }
            if(password1.val() == "") {
                alert("请输入新密码");
                password1.focus();
                return;
            }
            if(password2.val() == "") {
                alert("请确认新密码");
                password2.focus();
                return;
            }
            if(password1.length > 10 || password2.length > 10) {
                alert("密码格式有误");
                return;
            }
            if(password1.val() != password2.val()) {
                alert("确认密码不一致");
                password1.focus();
                return;
            }
            //向后端发送数据
            jQuery.ajax({
                url: "/blog/user/findpassword",
                type: "POST",                                                                                                                              
                data:{"username":username.val(),"password":password1.val(),"lover":lover.val()},
                success:function(result) {
                    if(result != null && result.code == 200 && result.data == 1) {
                        alert("成功找回密码！");
                        location.href = "login.html";
                        return;
                    } else {
                        alert("抱歉，找回失败");
                        return;
                    }
                }
            });
        }
    </script>
</body>

</html>